﻿using System;

namespace Microsoft.Services.Clab.UI.Mvvmc
{
    public static class ExceptionHandler
    {
        public static bool HandleWithExceptionHandler(ref Exception exception, Func<Exception, Exception> exceptionWrapper, Func<Exception, bool> exceptionHandler)
        {
            var handled = false;

            if (!(exception is ControllerException) && exceptionWrapper != null)
            {
                exception = exceptionWrapper(exception);
            }

            if (exceptionHandler != null)
            {
                handled = exceptionHandler(exception);
            }

            return handled;
        }
    }
}
